/*
 * Copyright (C) 2019 ByteDance Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bytedance.scene.animation.animatorexecutor;

import com.bytedance.scene.Scene;
import com.bytedance.scene.animation.AnimationInfo;
import com.bytedance.scene.animation.NavigationAnimatorExecutor;
import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorGroup;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.Component;

/**
 * Created by JiangQi on 8/9/18.
 */
public class DialogSceneAnimatorExecutor extends NavigationAnimatorExecutor {
    private static final long ANIMATION_DURATION = 150;

    @Override
    public boolean isSupport(Class<? extends Scene> from, Class<? extends Scene> to) {
        return true;
    }

    @Override
    protected boolean disableConfigAnimationDuration() {
        return true;
    }

    
    @Override
    protected Animator onPushAnimator(AnimationInfo from, final AnimationInfo to) {
        final Component toView = to.mSceneView;
        float toViewAlpha = toView.getAlpha();
        AnimatorProperty animatorProperty=new AnimatorProperty();
        animatorProperty.setTarget(toView)
                .alphaFrom(0.0f).alpha(toViewAlpha)
                .setCurveType(Animator.CurveType.CUBIC_BEZIER_DECELERATION)
                .setDuration(ANIMATION_DURATION);
        AnimatorGroup animatorGroup = new AnimatorGroup();
        animatorGroup.runParallel(animatorProperty);
        return animatorGroup;
    }

    
    @Override
    protected Animator onPopAnimator(final AnimationInfo fromInfo, final AnimationInfo toInfo) {
        AnimatorProperty animatorProperty=new AnimatorProperty();
        animatorProperty.setTarget(fromInfo.mSceneView)
                .alphaFrom(fromInfo.mSceneView.getAlpha()).alpha(0f)
                .setCurveType(Animator.CurveType.CUBIC_BEZIER_DECELERATION)
                .setDuration(ANIMATION_DURATION);
        AnimatorGroup animatorGroup = new AnimatorGroup();
        animatorGroup.runParallel(animatorProperty);
        return animatorGroup;
    }
}
